package com.touch.workshop.ui.classeditor;
import com.touch.core.Class;
import com.touch.workshop.Application;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceDragEvent;
import java.awt.dnd.DragSourceDropEvent;
import java.awt.dnd.DragSourceEvent;
import java.awt.dnd.DragSourceListener;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;
//TODO: draw sprites
public class ClassEditor extends JInternalFrame implements MouseListener, ActionListener, 
	DragSourceListener, DragGestureListener, DropTargetListener
{
	private static final long serialVersionUID = -4435340228000738192L;	
    public ClassEditor() 
    {
    	super("Class Editor", true, true, true, true);
        initComponents();   
        this.lstAvailableArchClasses.addMouseListener(this);
        this.lstArchClasses.addMouseListener(this);
        this.addArchClass.addActionListener(this);        
        this.renameArchClass.addActionListener(this);
        this.removeArchClass.addActionListener(this);
        this.removeFromAvailableClasses.addActionListener(this);
        this.menubar.FILE.NEW.addActionListener(this);
        this.menubar.FILE.SAVE.addActionListener(this);
        this.menubar.FILE.SAVEAS.addActionListener(this);
        
        dragSource = new DragSource();
        dragSource.createDefaultDragGestureRecognizer(lstAvailableArchClasses, DnDConstants.ACTION_COPY, this);
        new DropTarget(lstArchClasses, this);
    }
    private void initComponents() 
    {
    	if(ClassControls.ARCH_CLASSES == null)
    		ClassControls.ARCH_CLASSES = new DefaultListModel();
    	menubar = new ClassEditorMenuBar();
    	menuAvailableClasses = new JPopupMenu();
    	menuArchClasses = new JPopupMenu();
    	removeFromAvailableClasses = new JMenuItem("Remove ArchClass");
    	removeArchClass = new JMenuItem("Remove ArchClass");
    	addArchClass = new JMenuItem("Add ArchClass");
    	renameArchClass = new JMenuItem("Rename ArchClass");
    	archclasses = new DefaultListModel();
        pnlGeneralProperties = new JPanel();
        jScrollPane1 = new JScrollPane();
        lstArchClasses = new JList(archclasses);
        jScrollPane2 = new JScrollPane();
        lstAvailableArchClasses = new JList(ClassControls.ARCH_CLASSES);
        lblClassName = new JLabel();
        txtClassName = new JTextField();
        lblArchClasses = new JLabel();
        lblAvailableArchClasses = new JLabel();
        pnlSpriteProperties = new JPanel();
        lblLevelReq = new JLabel();
        spnLevelReq = new JSpinner();
        chkLocked = new JCheckBox();
        pnlMale = new JPanel();
        pnlFemale = new JPanel();
        lblMale = new JLabel();
        lblFemale = new JLabel();
        spnMaleSprite = new JSpinner();
        spnFemaleSprite = new JSpinner();
        pnlStats = new JPanel();
        lblSTR = new JLabel();
        spnSTR = new JSpinner();
        lblDEX = new JLabel();
        lblINT = new JLabel();
        lblSPT = new JLabel();
        spnDEX = new JSpinner();
        spnINT = new JSpinner();
        spnSPT = new JSpinner();
        pnlLocation = new JPanel();
        spnMap = new JSpinner();
        spnX = new JSpinner();
        spnY = new JSpinner();
        spnLayer = new JSpinner();
        lblMap = new JLabel();
        lblX = new JLabel();
        lblY = new JLabel();
        lblLayer = new JLabel();

        menuAvailableClasses.add(addArchClass);
        menuAvailableClasses.add(renameArchClass);
        menuArchClasses.add(removeArchClass);
        menuAvailableClasses.add(removeFromAvailableClasses);
        
        setJMenuBar(menubar);
        setTitle("Class Editor");
        
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

        pnlGeneralProperties.setBorder(BorderFactory.createEtchedBorder());

        jScrollPane1.setViewportView(lstArchClasses);

        jScrollPane2.setViewportView(lstAvailableArchClasses);

        lblClassName.setText("Class Name");

        lblArchClasses.setText("ArchClasses");

        lblAvailableArchClasses.setText("Available ArchClasses");

        GroupLayout pnlGeneralPropertiesLayout = new GroupLayout(pnlGeneralProperties);
        pnlGeneralProperties.setLayout(pnlGeneralPropertiesLayout);
        pnlGeneralPropertiesLayout.setHorizontalGroup(
            pnlGeneralPropertiesLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(pnlGeneralPropertiesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlGeneralPropertiesLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                    .addGroup(pnlGeneralPropertiesLayout.createSequentialGroup()
                        .addComponent(lblClassName)
                        .addGap(35, 35, 35)
                        .addComponent(txtClassName))
                    .addGroup(pnlGeneralPropertiesLayout.createSequentialGroup()
                        .addGroup(pnlGeneralPropertiesLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblArchClasses))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlGeneralPropertiesLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(lblAvailableArchClasses)
                            .addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE))
                        .addGap(6, 6, 6)))
                .addContainerGap(45, Short.MAX_VALUE))
        );
        pnlGeneralPropertiesLayout.setVerticalGroup(
            pnlGeneralPropertiesLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(pnlGeneralPropertiesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlGeneralPropertiesLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(lblClassName)
                    .addComponent(txtClassName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlGeneralPropertiesLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(lblArchClasses)
                    .addComponent(lblAvailableArchClasses))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlGeneralPropertiesLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 63, GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 63, GroupLayout.PREFERRED_SIZE))
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlSpriteProperties.setBorder(BorderFactory.createEtchedBorder());

        lblLevelReq.setText("Level Required");

        chkLocked.setText("Locked");

        pnlMale.setBorder(BorderFactory.createEtchedBorder());

        GroupLayout pnlMaleLayout = new GroupLayout(pnlMale);
        pnlMale.setLayout(pnlMaleLayout);
        pnlMaleLayout.setHorizontalGroup(
            pnlMaleLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        pnlMaleLayout.setVerticalGroup(
            pnlMaleLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        pnlFemale.setBorder(BorderFactory.createEtchedBorder());

        GroupLayout pnlFemaleLayout = new GroupLayout(pnlFemale);
        pnlFemale.setLayout(pnlFemaleLayout);
        pnlFemaleLayout.setHorizontalGroup(
            pnlFemaleLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        pnlFemaleLayout.setVerticalGroup(
            pnlFemaleLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        lblMale.setText("Male");

        lblFemale.setText("Female");

        GroupLayout pnlSpritePropertiesLayout = new GroupLayout(pnlSpriteProperties);
        pnlSpriteProperties.setLayout(pnlSpritePropertiesLayout);
        pnlSpritePropertiesLayout.setHorizontalGroup(
            pnlSpritePropertiesLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(pnlSpritePropertiesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlSpritePropertiesLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(chkLocked)
                    .addGroup(pnlSpritePropertiesLayout.createSequentialGroup()
                        .addComponent(lblLevelReq)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(spnLevelReq, GroupLayout.PREFERRED_SIZE, 89, GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlSpritePropertiesLayout.createSequentialGroup()
                        .addComponent(pnlMale, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlSpritePropertiesLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(pnlSpritePropertiesLayout.createSequentialGroup()
                                .addComponent(lblMale)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                                .addComponent(spnMaleSprite, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnlSpritePropertiesLayout.createSequentialGroup()
                                .addComponent(lblFemale)
                                .addGap(4, 4, 4)
                                .addComponent(spnFemaleSprite, GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)))))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlFemale, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31))
        );
        pnlSpritePropertiesLayout.setVerticalGroup(
            pnlSpritePropertiesLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(pnlSpritePropertiesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlSpritePropertiesLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(lblLevelReq)
                    .addComponent(spnLevelReq, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(chkLocked)
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlSpritePropertiesLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(pnlSpritePropertiesLayout.createSequentialGroup()
                        .addGroup(pnlSpritePropertiesLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(lblMale)
                            .addComponent(spnMaleSprite, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlSpritePropertiesLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(spnFemaleSprite, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblFemale)))
                    .addGroup(pnlSpritePropertiesLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                        .addComponent(pnlFemale, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addComponent(pnlMale, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        pnlStats.setBorder(BorderFactory.createTitledBorder(BorderFactory.createTitledBorder(""), "Base Stats"));

        lblSTR.setText("STR");

        lblDEX.setText("DEX");

        lblINT.setText("INT");

        lblSPT.setText("SPT");

        GroupLayout pnlStatsLayout = new GroupLayout(pnlStats);
        pnlStats.setLayout(pnlStatsLayout);
        pnlStatsLayout.setHorizontalGroup(
            pnlStatsLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(pnlStatsLayout.createSequentialGroup()
                .addGroup(pnlStatsLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(lblSTR)
                    .addComponent(lblDEX)
                    .addComponent(lblINT)
                    .addComponent(lblSPT))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlStatsLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(spnDEX, GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                    .addComponent(spnINT, GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                    .addComponent(spnSTR, GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                    .addComponent(spnSPT, GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE))
                .addContainerGap())
        );
        pnlStatsLayout.setVerticalGroup(
            pnlStatsLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(pnlStatsLayout.createSequentialGroup()
                .addGroup(pnlStatsLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(lblSTR)
                    .addComponent(spnSTR, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlStatsLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDEX)
                    .addComponent(spnDEX, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlStatsLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                    .addComponent(lblINT)
                    .addComponent(spnINT, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlStatsLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(lblSPT)
                    .addComponent(spnSPT, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
        );

        pnlLocation.setBorder(BorderFactory.createTitledBorder("Start Location"));

        lblMap.setText("Map");

        lblX.setText("X");

        lblY.setText("Y");

        lblLayer.setText("Layer");

        GroupLayout pnlLocationLayout = new GroupLayout(pnlLocation);
        pnlLocation.setLayout(pnlLocationLayout);
        pnlLocationLayout.setHorizontalGroup(
            pnlLocationLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(pnlLocationLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlLocationLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(lblMap)
                    .addComponent(lblX)
                    .addComponent(lblY)
                    .addComponent(lblLayer))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlLocationLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(spnX, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
                    .addComponent(spnMap, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
                    .addComponent(spnY, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
                    .addComponent(spnLayer, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        pnlLocationLayout.setVerticalGroup(
            pnlLocationLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(pnlLocationLayout.createSequentialGroup()
                .addGroup(pnlLocationLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(lblMap)
                    .addComponent(spnMap, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlLocationLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(lblX)
                    .addComponent(spnX, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlLocationLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(lblY)
                    .addComponent(spnY, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlLocationLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(lblLayer)
                    .addComponent(spnLayer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addContainerGap(49, Short.MAX_VALUE))
        );

        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
                    .addComponent(pnlSpriteProperties, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlGeneralProperties, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(pnlStats, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(pnlLocation, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(pnlStats, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE)
                    .addComponent(pnlGeneralProperties, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(pnlSpriteProperties, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(pnlLocation, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }       
	public void mouseClicked(MouseEvent e) 
	{		
		final Object source = e.getSource();
		if(e.getButton() == MouseEvent.BUTTON3)
		{
			if(source.equals(lstAvailableArchClasses))			
				this.menuAvailableClasses.show(lstAvailableArchClasses, e.getX(), e.getY());							
			else if(source.equals(lstArchClasses))
				this.menuArchClasses.show(lstArchClasses, e.getX(), e.getY());
		}
	}
	public void mouseEntered(MouseEvent arg0)	{}
	public void mouseExited(MouseEvent arg0) 	{}
	public void mousePressed(MouseEvent arg0) 	{}
	public void mouseReleased(MouseEvent arg0) 	{}
	public void actionPerformed(ActionEvent e) 
	{	
		String command = e.getActionCommand();
		Object source = e.getSource();
		if(source.equals(addArchClass))
		{
			String name = JOptionPane.showInputDialog(null, "ArchClass name");
			if(name == null)
				return;
			if(name.length() == 0)
				return;
			ClassControls.ARCH_CLASSES.addElement(name);				
		}
		else if(source.equals(renameArchClass))
		{
			int index = lstAvailableArchClasses.getSelectedIndex();
			if(index < 0)
				return;
			String newName = JOptionPane.showInputDialog(null, "New Class name");
			if(newName == null)
				return;
			if(newName.length() == 0)
				return;
			ClassControls.ARCH_CLASSES.set(index, newName);			
		}
		else if(source.equals(removeFromAvailableClasses))
		{
			int index = lstAvailableArchClasses.getSelectedIndex();
			if(index < 0)
				return;
			ClassControls.ARCH_CLASSES.remove(index);
		}
		else if(source.equals(removeArchClass))
		{
			int index = lstArchClasses.getSelectedIndex();
			if(index < 0)
				return;
			this.archclasses.remove(index);
		}
		else if(source.equals(menubar.FILE.SAVE))
		{
			Class c = new Class();
			for(int i = 0; i < this.archclasses.size(); i++)
			{
				String name = (String)this.archclasses.elementAt(i);
				c.archclass.add(name);
			}
			c.baseDEX = ((Integer)this.spnDEX.getValue()).intValue();
			c.baseINT = ((Integer)this.spnINT.getValue()).intValue();
			c.baseSPT = ((Integer)this.spnSPT.getValue()).intValue();
			c.baseSTR = ((Integer)this.spnSTR.getValue()).intValue();
			c.femaleSprite = ((Integer)this.spnFemaleSprite.getValue()).intValue();
			c.levelReq = ((Integer)this.spnLevelReq.getValue()).intValue();
			c.locked = this.chkLocked.isSelected();
			c.maleSprite = ((Integer)this.spnMaleSprite.getValue()).intValue();
			c.map = ((Integer)this.spnMap.getValue()).intValue();
			c.x = ((Integer)this.spnX.getValue()).intValue();
			c.y = ((Integer)this.spnY.getValue()).intValue();
			c.z = ((Integer)this.spnLayer.getValue()).intValue();
			
			ClassControls.CLASS_MAP.put(c.name, c);		
			this.dispose();
		}
		else if(source.equals(menubar.FILE.NEW))
		{
			ClassEditor editor = new ClassEditor();
			Application.vDesktop.add(editor);
			editor.setVisible(true);
		}
		else
			System.out.println("//TODO: Implement action: " + command);
	}
	public void dragDropEnd(DragSourceDropEvent dsde){}
	public void dragEnter(DragSourceDragEvent arg0) {}
	public void dragExit(DragSourceEvent arg0) {}
	public void dragOver(DragSourceDragEvent arg0) {}
	public void dropActionChanged(DragSourceDragEvent arg0) {}
	public void dragGestureRecognized(DragGestureEvent dge) 
	{		 
		 StringSelection transferable = new StringSelection(lstAvailableArchClasses.getSelectedValue().toString());
		 dragSource.startDrag(dge, DragSource.DefaultCopyDrop, transferable, this);
	}
	public void dragEnter(DropTargetDragEvent arg0) {}
	public void dragExit(DropTargetEvent arg0) {}
	public void dragOver(DropTargetDragEvent arg0) {}
	public void drop(DropTargetDropEvent dtde) 
	{					
		for(DataFlavor flavor: dtde.getTransferable().getTransferDataFlavors())
		{
			if(flavor.isMimeTypeEqual(DataFlavor.stringFlavor))
			{
				try {
					String element = (String)dtde.getTransferable().getTransferData(flavor);
					if(!this.archclasses.contains(element))
						this.archclasses.addElement(element);					
				}
				catch (Exception e) 
				{
					e.printStackTrace();
				}				
			}
			
		}
		dtde.acceptDrop(DnDConstants.ACTION_COPY);
	}
	public void dropActionChanged(DropTargetDragEvent arg0) {}
    protected JCheckBox chkLocked;
    protected JScrollPane jScrollPane1;
    protected JScrollPane jScrollPane2;
    protected JLabel lblArchClasses;
    protected JLabel lblAvailableArchClasses;
    protected JLabel lblClassName;
    protected JLabel lblDEX;
    protected JLabel lblFemale;
    protected JLabel lblINT;
    protected JLabel lblLayer;
    protected JLabel lblLevelReq;
    protected JLabel lblMale;
    protected JLabel lblMap;
    protected JLabel lblSPT;
    protected JLabel lblSTR;
    protected JLabel lblX;
    protected JLabel lblY;
    protected JList lstArchClasses;
    protected JList lstAvailableArchClasses;
    protected JPanel pnlFemale;
    protected JPanel pnlGeneralProperties;
    protected JPanel pnlLocation;
    protected JPanel pnlMale;
    protected JPanel pnlSpriteProperties;
    protected JPanel pnlStats;
    protected JSpinner spnDEX;
    protected JSpinner spnFemaleSprite;
    protected JSpinner spnINT;
    protected JSpinner spnLayer;
    protected JSpinner spnLevelReq;
    protected JSpinner spnMaleSprite;
    protected JSpinner spnMap;
    protected JSpinner spnSPT;
    protected JSpinner spnSTR;
    protected JSpinner spnX;
    protected JSpinner spnY;
    protected JTextField txtClassName; 
    protected DefaultListModel archclasses;
    protected JPopupMenu menuAvailableClasses;
    protected JPopupMenu menuArchClasses;
    protected JMenuItem removeArchClass;
    protected JMenuItem addArchClass;
    protected JMenuItem renameArchClass;    
    protected JMenuItem removeFromAvailableClasses;
    protected DragSource dragSource;
    protected ClassEditorMenuBar menubar;
}
